import type { VbenFormSchema } from '#/adapter/form';

// 表单配置
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'name',
      label: '商品名称',
      componentProps: {
        placeholder: '请输入商品名称',
      },
      rules: 'required',
    },
    {
      component: 'Select',
      fieldName: 'categoryId',
      label: '商品分类',
      componentProps: {
        placeholder: '请选择商品分类',
      },
      rules: 'required',
    },
    {
      component: 'Upload',
      fieldName: 'pic',
      label: '商品图片',
      componentProps: {
        listType: 'picture-card',
        limit: 1,
      },
      rules: 'required',
    },
    {
      component: 'InputNumber',
      fieldName: 'credit',
      label: '积分',
      componentProps: {
        min: 0,
        placeholder: '请输入积分',
      },
      rules: 'required',
    },
    {
      component: 'InputNumber',
      fieldName: 'price',
      label: '价格',
      componentProps: {
        min: 0,
        placeholder: '请输入价格',
      },
      rules: 'required',
    },
    {
      component: 'Input',
      fieldName: 'storeName',
      label: '领取门店',
      componentProps: {
        placeholder: '请输入领取门店',
      },
    },
    {
      component: 'Input',
      fieldName: 'storeAddress',
      label: '门店地址',
      componentProps: {
        placeholder: '请输入门店地址',
      },
    },
    {
      component: 'Input',
      fieldName: 'description',
      label: '描述',
      componentProps: {
        type: 'textarea',
        rows: 4,
        placeholder: '请输入商品描述',
      },
    },
    {
      component: 'Switch',
      fieldName: 'shelf',
      label: '上架状态',
      componentProps: {
        activeValue: 1,
        inactiveValue: 0,
      },
    },
    {
      component: 'InputNumber',
      fieldName: 'stock',
      label: '库存',
      componentProps: {
        min: 0,
        placeholder: '请输入库存数量',
      },
      rules: 'required',
    },
  ];
}

// 搜索表单配置
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'name',
      label: '商品名称',
    },
    {
      component: 'Select',
      fieldName: 'categoryId',
      label: '商品分类',
      componentProps: {
        allowClear: true,
      },
    },
    {
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          { label: '已上架', value: 1 },
          { label: '已下架', value: 0 },
        ],
      },
      fieldName: 'shelf',
      label: '上架状态',
    },
  ];
}

// 表格列配置
export function useColumns() {
  return [
    {
      title: '商品名称',
      field: 'name',
      width: 200,
    },
    {
      title: '商品分类',
      field: 'categoryName',
      width: 120,
    },
    {
      title: '商品图片',
      field: 'pic',
      width: 100,
      slots: {
        default: ({ row }) => {
          return row.pic ? <el-image src={row.pic} style="width: 50px; height: 50px" /> : '-';
        },
      },
    },
    {
      title: '积分',
      field: 'credit',
      width: 100,
    },
    {
      title: '价格',
      field: 'price',
      width: 100,
    },
    {
      title: '领取门店',
      field: 'storeName',
      width: 150,
    },
    {
      title: '库存',
      field: 'stock',
      width: 100,
    },
    {
      title: '上架状态',
      field: 'shelf',
      width: 100,
      slots: {
        default: ({ row }) => {
          return row.shelf === 1 ? '已上架' : '已下架';
        },
      },
    },
    {
      title: '创建时间',
      field: 'createTime',
      width: 180,
    },
    {
      title: '操作',
      field: 'operate',
      width: 160,
      fixed: 'right',
    },
  ];
} 